Skip to content

Check for an abort before each start in the dispatcher - #121

Merged
HalRiveria merged 4 commits into
mainfrom
fix/dispatcher-start-abort
Dec 3, 2026
Merged

HalRiveria merged 4 commits into
mainfrom
fix/dispatcher-start-abort

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

Depends on #120, merge after it.

What was wrong: since #114 the dispatcher checks for an abort at the top of each pass and after -PollCallback. Its start loop still read only the token, which that check cancels. So an abort that arrived while the loop was starting programs went unseen until the next pass, and every free slot on the current pass was still filled. That covers a Ctrl+C landing mid-loop and a -JobStarter calling Request-PkAbort. The extra programs were drained as usual, so nothing leaked, but they shouldn't have started.

What changed: the start loop's condition also reads [PkConsoleCtrl]::AbortRequested before each job, as the runspace engine's launch loop has since #114. That's a field read per job, not a function call. It comes before the shared budget's Wait(0), so an abort never takes a slot for a job that won't start.

How it was tested: harness section O runs a -JobStarter that requests an abort on its first call, with 6 jobs and -MaxConcurrent 3. It runs once with a plain limit and once with a shared SemaphoreSlim budget of 3, checking that no slot is left taken.

Before the fix (Windows PowerShell 5.1 and PowerShell 7, the same on both):

[FAIL] dispatch: a -JobStarter that requests an abort starts nothing more after its own program (started 3 of 6)
[FAIL] and on a shared budget, without taking a slot it doesn't use (started 3 of 6, 3 of 3 slots free after)

After: started 1 of 6, and 3 of 3 slots free after.

Full harness: all 776 assertions pass on Windows PowerShell 5.1 and on PowerShell 7.

The dispatcher checks for an abort once per pass, and its start loop read only the token, which that check cancels. So a Ctrl+C landing while the loop was starting programs, or a -JobStarter that requested an abort, still filled every free slot on that pass. The start loop now also reads the abort flag before each job, ahead of the shared budget's Wait(0) so no slot is taken for a job that won't start. Harness section O covers a -JobStarter that requests an abort, with a plain limit and with a shared budget.
The test that kills a live tree listed beside a disposed process counted leftover pings right after Stop-PkProcessTree returned. Ending a Job Object returns before Windows has finished tearing its processes down, so on a CI runner the ping was still listed once. It now waits up to 5 seconds for it to go, as the other kill tests do.
Base automatically changed from docs/argument-string-row-cmd to main December 3, 2026 02:02
@HalRiveria
HalRiveria merged commit 0a8c8ac into main Dec 3, 2026
3 checks passed
@HalRiveria
HalRiveria deleted the fix/dispatcher-start-abort branch December 3, 2026 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants